package com.huawei.appmarket.service.appmgr.view.activity;

import android.app.ActionBar;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.huawei.android.app.ActionBarEx;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.toolbar.ToolBarIcon;
import com.huawei.appmarket.service.appmgr.protocol.AppInstallFragmentProtocol;
import com.huawei.appmarket.service.appmgr.protocol.AppInstallFragmentProtocol.Request;
import com.huawei.appmarket.service.appmgr.view.activity.fragment.AppInstallFragment;
import com.huawei.appmarket.service.appmgr.view.widget.FixedTextLinearLayout;
import com.huawei.secure.android.common.intent.SafeIntent;
import o.azb;
import o.azc;
import o.cgv;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cnw;
import o.dgh;
import o.Logger;
import o.ContentManager;
import o.dsg;
import o.dsx;
import o.dta.e;
import o.dtb;
import o.dtj;
import o.dwc;
import o.eib;
import o.epv;
import o.epw;
import o.epx.a;
import o.evx;
import o.ewm;
import o.ewm$g;
import o.ewm.c;
import o.ewm.h;
import o.ewm.i;
import o.ewm.j;
import o.ewm.n;
import o.fho;
import o.fhz;
import o.ll;

public class AppInstallActivity extends BaseActivity<AppManagerProtocol> implements OnClickListener, dsg {
    private ImageView ʻॱ;
    private Menu ʽॱ;
    private dtb ʾ = dtb.ॱ();
    private View ʿ;
    private AppInstallFragment ˈ;
    private TextView ˉ;
    private TextView ˊˊ;
    private LinearLayout ˊˋ;
    private ToolBarIcon ˊॱ;
    private ImageView ˊᐝ;
    private FixedTextLinearLayout ˋˊ;
    private View ˋˋ;
    private ToolBarIcon ˋॱ;
    private View ˋᐝ;
    private View ˌ;
    private View ˍ;
    private View ˎˎ;
    private ToolBarIcon ˏॱ;
    private boolean ˑ;
    private View ͺ;
    private boolean ॱˊ = false;
    private LinearLayout ॱˋ;
    private dtj ॱˎ = new dtj();
    private ToolBarIcon ᐝॱ;

    public void onCreate(Bundle bundle) {
        boolean z;
        super.onCreate(bundle);
        setContentView(h.ॱˊ);
        fhz ˋ = fho.ˏ().ˋ("PackageManager");
        if (!(ˋ == null || (((cnw) ˋ.ॱ(cnw.class)).ˏ(getApplicationContext()) & 2) == 0)) {
            this.ˑ = true;
        }
        cgv.ˋ(this, c.ˎ, this.ˑ ? c.ˋ : c.ॱˎ);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(c.ॱˎ));
        SafeIntent safeIntent = new SafeIntent(getIntent());
        boolean booleanExtra = safeIntent.getBooleanExtra("app_install_open_edit", false);
        dtj o_dtj = this.ॱˎ;
        if (azc.ˎ().ॱ() >= 21) {
            z = true;
        } else {
            z = false;
        }
        o_dtj.ॱ(z);
        Logger.ˎ("AppInstallActivity", "onCreate isEdit:" + booleanExtra + ",isEmui:" + this.ॱˎ.ˏ());
        eib.ॱ(this);
        ʽ(booleanExtra);
        String str = "";
        String str2 = "";
        if (getIntent() != null) {
            this.ॱˊ = safeIntent.getBooleanExtra("isFromAppManager", false);
            Object stringExtra = safeIntent.getStringExtra("eventkey");
            str = safeIntent.getStringExtra("eventvalue");
        } else {
            String str3 = str;
            str = str2;
        }
        AppManagerProtocol appManagerProtocol = (AppManagerProtocol) ʾ();
        if (appManagerProtocol != null) {
            stringExtra = appManagerProtocol.ˊ().ˏ();
            str = appManagerProtocol.ˊ().ˋ();
            dwc.ॱ().ˊ(this, appManagerProtocol.ˊ().ˎ(), null);
        }
        if (!TextUtils.isEmpty(stringExtra)) {
            dgh.ॱ(this, stringExtra, str);
        }
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        int i = getResources().getConfiguration().orientation;
        if (this.ॱˎ.ˏ()) {
            ॱ(menu, i);
        } else {
            ॱ(i);
        }
        return true;
    }

    private void ॱ(int i) {
        if (this.ͺ == null) {
            return;
        }
        if (dtb.ॱ().ˏ().isEmpty()) {
            this.ͺ.setVisibility(8);
            this.ˌ.setVisibility(8);
        } else if (2 == i) {
            this.ͺ.setVisibility(8);
            if (this.ˌ == null) {
                return;
            }
            if (this.ˑ) {
                this.ˌ.setVisibility(0);
            } else {
                this.ˌ.setVisibility(8);
            }
        } else {
            this.ˌ.setVisibility(8);
            if (this.ˑ) {
                this.ͺ.setVisibility(0);
            } else {
                this.ͺ.setVisibility(8);
            }
        }
    }

    private void ॱ(Menu menu, int i) {
        if (this.ͺ != null) {
            this.ͺ.setVisibility(8);
            if (this.ˑ && menu != null) {
                if (2 == i) {
                    menu.clear();
                    if (azc.ˎ().ॱॱ() && azc.ˋ(this) == 0) {
                        getMenuInflater().inflate(ewm$g.ˎ, menu);
                    } else {
                        getMenuInflater().inflate(ewm$g.ˊ, menu);
                    }
                } else {
                    menu.clear();
                    getMenuInflater().inflate(ewm$g.ˎ, menu);
                }
                this.ʽॱ = menu;
                ˎ(menu);
            }
        }
    }

    private void ˎ(Menu menu) {
        if (menu == null || this.ˈ == null) {
            Logger.e("AppInstallActivity", "menu = " + menu + ", appInstallFragment = " + this.ˈ);
            return;
        }
        if (this.ͺ != null) {
            this.ͺ.setVisibility(8);
        }
        if (!this.ˑ || this.ʾ.ˏ().isEmpty()) {
            menu.clear();
            return;
        }
        if (menu.size() <= 0) {
            boolean z = 2 != getResources().getConfiguration().orientation || (azc.ˎ().ॱॱ() && azc.ˋ(this) == 0);
            if (z) {
                getMenuInflater().inflate(ewm$g.ˎ, menu);
            } else {
                getMenuInflater().inflate(ewm$g.ˊ, menu);
            }
            this.ʽॱ = menu;
        }
        if (this.ˈ.ˊʽ()) {
            menu.findItem(j.ᶥॱ).setVisible(false);
            if (this.ˈ.ˌॱ()) {
                menu.findItem(j.ᵢ).setVisible(false);
                menu.findItem(j.ㆍॱ).setVisible(true);
            } else {
                menu.findItem(j.ㆍॱ).setVisible(false);
                menu.findItem(j.ᵢ).setVisible(true);
            }
            MenuItem findItem = menu.findItem(j.ᴵ);
            findItem.setVisible(true);
            resetUninstallMenu(findItem);
            return;
        }
        menu.findItem(j.ᶥॱ).setVisible(true);
        menu.findItem(j.ᴵ).setVisible(false);
        menu.findItem(j.ᵢ).setVisible(false);
        menu.findItem(j.ㆍॱ).setVisible(false);
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId != 16908332) {
            return ˎ(itemId);
        }
        finish();
        return true;
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        if (this.ॱˎ != null && configuration != null) {
            if (this.ॱˎ.ˏ()) {
                ॱ(this.ʽॱ, configuration.orientation);
            } else {
                ॱ(configuration.orientation);
            }
        }
    }

    public void onResume() {
        super.onResume();
        dsx.ˏ(e.ˏ);
    }

    public void onPause() {
        super.onPause();
    }

    public void ˎ(boolean z) {
        ͺ();
        if (this.ॱˎ.ˏ()) {
            ˊ(z);
        } else {
            ˏ(z);
        }
    }

    private void ˏ(boolean z) {
        this.ʿ.setVisibility(0);
        if (getActionBar() != null) {
            getActionBar().hide();
        }
        if (z) {
            this.ˊᐝ.setImageResource(ewm.e.ॱͺ);
            this.ˊˋ.setContentDescription(getString(n.ˊˈ));
            this.ˊˋ.setOnClickListener(new OnClickListener(this) {
                final /* synthetic */ AppInstallActivity ˏ;

                {
                    this.ˏ = r1;
                }

                public void onClick(View view) {
                    this.ˏ.ˈ.ॱˊ(false);
                    this.ˏ.ˈ.ʿॱ();
                    ll.ˏ(ContentManager.getInstant().getContext()).ˋ(new Intent(a.ˏ));
                }
            });
            this.ˊˊ.setVisibility(0);
            ॱˊ();
            return;
        }
        this.ˊᐝ.setImageResource(ewm.e.ˊˋ);
        this.ˊˋ.setContentDescription(getString(n.ॱˌ));
        this.ˊˋ.setOnClickListener(new evx(this) {
            final /* synthetic */ AppInstallActivity ॱ;

            {
                this.ॱ = r1;
            }

            public void ˋ(View view) {
                this.ॱ.onBackPressed();
            }
        });
        this.ˊˊ.setVisibility(0);
        this.ˊˊ.setText(n.ꜟˏ);
        this.ˉ.setVisibility(8);
        this.ˋˊ.ˏ();
    }

    private void ॱˊ() {
        if (this.ˈ == null) {
            Logger.e("AppInstallActivity", "appInstallFragment == null");
            return;
        }
        AppInstallFragment.c ˊʼ = this.ˈ.ˊʼ();
        if (ˊʼ.ॱ > 0) {
            this.ˊˊ.setText(getResources().getQuantityString(i.ˎ, ˊʼ.ॱ, new Object[]{Integer.valueOf(ˊʼ.ॱ)}));
            this.ˉ.setText(epw.ˊ(ˊʼ.ˏ));
            this.ˉ.setVisibility(0);
            this.ˋˊ.ˏ();
            return;
        }
        this.ˊˊ.setText(n.ʼॱ);
        this.ˉ.setVisibility(8);
        this.ˋˊ.ˏ();
    }

    private void ˊ(boolean z) {
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            if (z) {
                AppInstallFragment.c ˊʼ = this.ˈ.ˊʼ();
                actionBar.setDisplayHomeAsUpEnabled(false);
                if (ˊʼ.ॱ > 0) {
                    actionBar.setTitle(getResources().getQuantityString(i.ˎ, ˊʼ.ॱ, new Object[]{Integer.valueOf(ˊʼ.ॱ)}));
                    actionBar.setSubtitle(epw.ˊ(ˊʼ.ˏ));
                } else {
                    actionBar.setTitle(n.ʼॱ);
                    actionBar.setSubtitle(null);
                }
                Drawable drawable = getResources().getDrawable(ewm.e.ॱͺ);
                if (drawable != null) {
                    ActionBarEx.setStartIcon(getActionBar(), true, drawable, new OnClickListener(this) {
                        final /* synthetic */ AppInstallActivity ˊ;

                        {
                            this.ˊ = r1;
                        }

                        public void onClick(View view) {
                            this.ˊ.ˈ.ॱˊ(false);
                            this.ˊ.ˈ.ˉॱ();
                            ll.ˏ(ContentManager.getInstant().getContext()).ˋ(new Intent(a.ˏ));
                        }
                    });
                }
            } else {
                ActionBarEx.setStartIcon(actionBar, false, null, null);
                actionBar.setDisplayHomeAsUpEnabled(true);
                actionBar.setTitle(n.ꜟˏ);
                actionBar.setSubtitle(null);
                actionBar.show();
            }
            this.ʿ.setVisibility(8);
        }
    }

    private void ͺ() {
        if (this.ˈ == null) {
            Logger.e("AppInstallActivity", "initNonEmuiTitleView, appInstallFragment == null");
        } else if (this.ʿ == null) {
            this.ʿ = findViewById(j.ˈᐧ);
            this.ˋˊ = (FixedTextLinearLayout) findViewById(j.ʽʾ);
            this.ˊˋ = (LinearLayout) findViewById(j.ߺˎ);
            this.ˊᐝ = (ImageView) findViewById(j.ʽˌ);
            this.ˊˊ = (TextView) findViewById(j.ˇˊ);
            this.ˉ = (TextView) findViewById(j.ʾꜟ);
            this.ˍ = this.ʿ.findViewById(j.ˈʼ);
            this.ˍ.setOnClickListener(this);
            this.ˋᐝ = this.ʿ.findViewById(j.ʿʻ);
            this.ˋᐝ.setOnClickListener(this);
            this.ˎˎ = this.ʿ.findViewById(j.ˈʽ);
            this.ˎˎ.setOnClickListener(this);
            this.ˋˋ = this.ʿ.findViewById(j.ˈʻ);
            this.ˋˋ.setOnClickListener(this);
        }
    }

    private void ʽ(boolean z) {
        azb.ˏ(findViewById(j.ˈᐧ));
        int ˊ = epv.ˊ(this, 2);
        this.ͺ = findViewById(j.ꓸॱ);
        this.ˋॱ = (ToolBarIcon) findViewById(j.ᶥॱ);
        this.ˋॱ.setOnClickListener(this);
        ˊ(this.ˋॱ, ˊ);
        this.ˏॱ = (ToolBarIcon) findViewById(j.ᵢ);
        this.ˏॱ.setOnClickListener(this);
        ˊ(this.ˏॱ, ˊ);
        this.ˊॱ = (ToolBarIcon) findViewById(j.ㆍॱ);
        this.ˊॱ.setOnClickListener(this);
        ˊ(this.ˊॱ, ˊ);
        this.ᐝॱ = (ToolBarIcon) findViewById(j.ᴵ);
        this.ᐝॱ.setOnClickListener(this);
        ˊ(this.ᐝॱ, ˊ);
        this.ˌ = findViewById(j.ʳˋ);
        this.ॱˋ = (LinearLayout) findViewById(j.ˈʻ);
        this.ʻॱ = (ImageView) findViewById(j.ˈﾞ);
        Fragment ᐝ = ᐝ(z);
        if (ᐝ instanceof AppInstallFragment) {
            this.ˈ = (AppInstallFragment) ᐝ;
        }
    }

    private Fragment ᐝ(boolean z) {
        Request request = new Request();
        request.ˊ(z);
        request.ॱ(true);
        cjo appInstallFragmentProtocol = new AppInstallFragmentProtocol();
        appInstallFragmentProtocol.ˊ(request);
        Fragment ˊ = cjk.ˎ().ˊ(new cjm("installmgr.fragment", appInstallFragmentProtocol));
        if (!(ˊ instanceof TaskFragment)) {
            return ˊ;
        }
        ((TaskFragment) ˊ).ˋ(ˏॱ(), j.ﾞˋ, "installmgr.fragment");
        Fragment findFragmentByTag = ˏॱ().findFragmentByTag("installmgr.fragment");
        if (findFragmentByTag != null) {
            return findFragmentByTag;
        }
        return ˊ;
    }

    public void ॱ(boolean z) {
        if (this.ˈ == null) {
            Logger.e("AppInstallActivity", "appInstallFragment == null");
        } else if (this.ॱˎ.ˏ()) {
            ˎ(this.ʽॱ);
        } else if (!this.ˑ || this.ʾ.ˏ().isEmpty()) {
            this.ͺ.setVisibility(8);
            this.ˌ.setVisibility(8);
        } else {
            if (2 == getResources().getConfiguration().orientation) {
                this.ͺ.setVisibility(8);
                this.ˌ.setVisibility(0);
            } else {
                this.ͺ.setVisibility(0);
                this.ˌ.setVisibility(8);
            }
            if (z) {
                this.ˋॱ.setVisibility(8);
                this.ˍ.setVisibility(8);
                this.ᐝॱ.setVisibility(0);
                ॱ(this.ᐝॱ);
                this.ˋˋ.setVisibility(0);
                if (this.ˈ.ˌॱ()) {
                    this.ˊॱ.setVisibility(0);
                    this.ˏॱ.setVisibility(8);
                    this.ˎˎ.setVisibility(0);
                    this.ˋᐝ.setVisibility(8);
                    return;
                }
                this.ˊॱ.setVisibility(8);
                this.ˏॱ.setVisibility(0);
                this.ˎˎ.setVisibility(8);
                this.ˋᐝ.setVisibility(0);
                return;
            }
            this.ˋॱ.setVisibility(0);
            this.ˏॱ.setVisibility(8);
            this.ˊॱ.setVisibility(8);
            this.ᐝॱ.setVisibility(8);
            this.ˍ.setVisibility(0);
            this.ˋᐝ.setVisibility(8);
            this.ˎˎ.setVisibility(8);
            this.ˋˋ.setVisibility(8);
        }
    }

    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (4 == i) {
            if (this.ˈ == null) {
                Logger.e("AppInstallActivity", "onKeyDown, appInstallFragment == null");
                return false;
            } else if (this.ˈ.ˊʽ()) {
                this.ˈ.ॱˊ(false);
                this.ˈ.ʿॱ();
                this.ˈ.ˋॱ(true);
                return true;
            } else if (this.ॱˊ) {
                finish();
                Intent intent = new Intent("android.intent.action.MAIN");
                intent.setFlags(268435456);
                intent.addCategory("android.intent.category.HOME");
                startActivity(intent);
            }
        }
        return super.onKeyDown(i, keyEvent);
    }

    public void onClick(View view) {
        ˎ(view.getId());
    }

    private boolean ˎ(int i) {
        if (this.ˈ == null) {
            Logger.e("AppInstallActivity", "appInstallFragment == null");
            return false;
        }
        if (i == j.ᶥॱ || i == j.ˈʼ) {
            this.ˈ.ʽᐝ();
        } else if (i == j.ᵢ || i == j.ʿʻ) {
            this.ˈ.ʼᐝ();
        } else if (i == j.ᴵ || i == j.ˈʻ) {
            this.ˈ.ˊʻ();
        } else if (i != j.ㆍॱ && i != j.ˈʽ) {
            return false;
        } else {
            this.ˈ.ˉॱ();
        }
        return true;
    }

    private void ˊ(ToolBarIcon toolBarIcon, int i) {
        LayoutParams layoutParams = (LayoutParams) toolBarIcon.getLayoutParams();
        layoutParams.gravity = 17;
        layoutParams.width = i;
        toolBarIcon.setLayoutParams(layoutParams);
    }

    public boolean ᐝ() {
        if (this.ˈ == null || this.ˈ.ˈॱ() == null || this.ˈ.ˈॱ().size() <= 0) {
            return false;
        }
        return true;
    }

    public void resetUninstallMenu(MenuItem menuItem) {
        if (ᐝ()) {
            menuItem.setIcon(ewm.e.ͺˏ);
            menuItem.setTitle(n.ʾ);
            menuItem.setEnabled(true);
            return;
        }
        CharSequence spannableString = new SpannableString(menuItem.getTitle());
        spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(c.ˊॱ)), 0, spannableString.length(), 0);
        menuItem.setTitle(spannableString);
        menuItem.setEnabled(false);
    }

    public void ॱ(ToolBarIcon toolBarIcon) {
        boolean z = false;
        try {
            int i;
            TextView textView = (TextView) toolBarIcon.getChildAt(0);
            int ˋ = epv.ˋ(ContentManager.getInstant().getContext(), 24);
            int i2 = ewm.e.ͺˏ;
            int color = getResources().getColor(c.ˏॱ);
            toolBarIcon.setEnabled(true);
            if (ᐝ()) {
                z = true;
                i = color;
                color = i2;
            } else {
                color = ewm.e.ᐧ;
                i = getResources().getColor(c.ˊॱ);
                toolBarIcon.setEnabled(false);
            }
            Drawable drawable = ContentManager.getInstant().getContext().getResources().getDrawable(color);
            drawable.setBounds(0, 0, ˋ, ˋ);
            textView.setCompoundDrawables(null, drawable, null, null);
            textView.setTextColor(i);
            this.ॱˋ.setClickable(z);
            this.ʻॱ.setImageResource(color);
        } catch (Exception e) {
            Logger.e("AppInstallActivity", "resetUnintallBtn error:" + e.getMessage());
        }
    }
}
